<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
  Class: RJMetrics::Client
  
    &mdash; Documentation by YARD 0.8.7.4
  
</title>

  <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />

  <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  hasFrames = window.top.frames.main ? true : false;
  relpath = '../';
  framesUrl = "../frames.html#!RJMetrics/Client.html";
</script>


  <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>


  </head>
  <body>
    <div id="header">
      <div id="menu">
  
    <a href="../_index.html">Index (C)</a> &raquo;
    <span class='title'><span class='object_link'><a href="../RJMetrics.html" title="RJMetrics (module)">RJMetrics</a></span></span>
     &raquo; 
    <span class="title">Client</span>
  

  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="../class_list.html">
      Class List
    </a>
  
    <a class="full_list_link" id="method_list_link"
        href="../method_list.html">
      Method List
    </a>
  
    <a class="full_list_link" id="file_list_link"
        href="../file_list.html">
      File List
    </a>
  
</div>
      <div class="clear"></div>
    </div>

    <iframe id="search_frame"></iframe>

    <div id="content"><h1>Class: RJMetrics::Client
  
  
  
</h1>

<dl class="box">
  
    <dt class="r1">Inherits:</dt>
    <dd class="r1">
      <span class="inheritName">Object</span>
      
        <ul class="fullTree">
          <li>Object</li>
          
            <li class="next">RJMetrics::Client</li>
          
        </ul>
        <a href="#" class="inheritanceTree">show all</a>
      
      </dd>
    
  
  
    
  
    
  
  
  
    <dt class="r2 last">Defined in:</dt>
    <dd class="r2 last">lib/rjmetrics-client/client.rb</dd>
  
</dl>
<div class="clear"></div>

<h2>Defined Under Namespace</h2>
<p class="children">
  
    
  
    
      <strong class="classes">Classes:</strong> <span class='object_link'><a href="Client/InvalidRequestException.html" title="RJMetrics::Client::InvalidRequestException (class)">InvalidRequestException</a></span>, <span class='object_link'><a href="Client/InvalidResponseException.html" title="RJMetrics::Client::InvalidResponseException (class)">InvalidResponseException</a></span>, <span class='object_link'><a href="Client/UnableToConnectException.html" title="RJMetrics::Client::UnableToConnectException (class)">UnableToConnectException</a></span>
    
  
</p>

  <h2>Constant Summary</h2>
  
    <dl class="constants">
      
        <dt id="API_BASE-constant" class="">API_BASE =
          <div class="docstring">
  <div class="discussion">
    
<p>default RJMetrics Data Import API url</p>


  </div>
</div>
<div class="tags">
  

</div>
        </dt>
        <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>https://connect.rjmetrics.com/v2</span><span class='tstring_end'>&quot;</span></span></pre></dd>
      
        <dt id="SANDBOX_BASE-constant" class="">SANDBOX_BASE =
          <div class="docstring">
  <div class="discussion">
    
<p>RJMetrics Sandbox API url</p>


  </div>
</div>
<div class="tags">
  

</div>
        </dt>
        <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>https://sandbox-connect.rjmetrics.com/v2</span><span class='tstring_end'>&quot;</span></span></pre></dd>
      
        <dt id="BATCH_SIZE-constant" class="">BATCH_SIZE =
          <div class="docstring">
  <div class="discussion">
    
<p>Datapoints to push at a time</p>


  </div>
</div>
<div class="tags">
  

</div>
        </dt>
        <dd><pre class="code"><span class='int'>100</span></pre></dd>
      
        <dt id="DEFAULT_TIMEOUT_SECONDS-constant" class="">DEFAULT_TIMEOUT_SECONDS =
          <div class="docstring">
  <div class="discussion">
    
<p>Timout Seconds</p>


  </div>
</div>
<div class="tags">
  

</div>
        </dt>
        <dd><pre class="code"><span class='int'>10</span></pre></dd>
      
    </dl>
  







  
    <h2>
      Instance Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#authenticated%3F-instance_method" title="#authenticated? (instance method)">- (Boolean) <strong>authenticated?</strong> </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Checks if the provided Client ID and API Key are valid credentials by
requesting from the RJMetrics API Sandbox.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#initialize-instance_method" title="#initialize (instance method)">- (Client) <strong>initialize</strong>(client_id, api_key, timeout_in_seconds = DEFAULT_TIMEOUT_SECONDS) </a>
    

    
  </span>
  
  
    <span class="note title constructor">constructor</span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Constructs a Client instance if it receives valid arguments or will raise
an ArgumentError.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#pushData-instance_method" title="#pushData (instance method)">- (Array) <strong>pushData</strong>(table_name, data, url = API_BASE) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Sends data to RJMetrics Data Import API in batches of 100.</p>
</div></span>
  
</li>

      
    </ul>
  

<div id="constructor_details" class="method_details_list">
  <h2>Constructor Details</h2>
  
    <div class="method_details first">
  <h3 class="signature first" id="initialize-instance_method">
  
    - (<tt><span class='object_link'><a href="" title="RJMetrics::Client (class)">Client</a></span></tt>) <strong>initialize</strong>(client_id, api_key, timeout_in_seconds = DEFAULT_TIMEOUT_SECONDS) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>Constructs a Client instance if it receives valid arguments or will raise
an ArgumentError.</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>client_id</span>
      
      
        <span class='type'>(<tt>Integer</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>your RJMetrics Client ID</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>api_key</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>your RJMetrics API Key</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>timeout_in_seconds</span>
      
      
        <span class='type'>(<tt>Integer</tt>)</span>
      
      
        <em class="default">(defaults to: <tt>DEFAULT_TIMEOUT_SECONDS</tt>)</em>
      
      
        &mdash;
        <div class='inline'>
<p>seconds to wait for API responses</p>
</div>
      
    </li>
  
</ul>


</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


26
27
28
29
30
31</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/rjmetrics-client/client.rb', line 26</span>

<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_client_id'>client_id</span><span class='comma'>,</span> <span class='id identifier rubyid_api_key'>api_key</span><span class='comma'>,</span> <span class='id identifier rubyid_timeout_in_seconds'>timeout_in_seconds</span> <span class='op'>=</span> <span class='const'>DEFAULT_TIMEOUT_SECONDS</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_validateConstructorArgs'>validateConstructorArgs</span><span class='lparen'>(</span><span class='id identifier rubyid_client_id'>client_id</span><span class='comma'>,</span> <span class='id identifier rubyid_api_key'>api_key</span><span class='comma'>,</span> <span class='id identifier rubyid_timeout_in_seconds'>timeout_in_seconds</span><span class='rparen'>)</span>
  <span class='ivar'>@client_id</span> <span class='op'>=</span> <span class='id identifier rubyid_client_id'>client_id</span>
  <span class='ivar'>@api_key</span> <span class='op'>=</span> <span class='id identifier rubyid_api_key'>api_key</span>
  <span class='ivar'>@timeout_in_seconds</span> <span class='op'>=</span> <span class='id identifier rubyid_timeout_in_seconds'>timeout_in_seconds</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
  
</div>


  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="authenticated?-instance_method">
  
    - (<tt>Boolean</tt>) <strong>authenticated?</strong> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>Checks if the provided Client ID and API Key are valid credentials by
requesting from the RJMetrics API Sandbox.</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Boolean</tt>)</span>
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


34
35
36
37
38
39
40
41
42</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/rjmetrics-client/client.rb', line 34</span>

<span class='kw'>def</span> <span class='id identifier rubyid_authenticated?'>authenticated?</span>
  <span class='id identifier rubyid_test_data'>test_data</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='symbol'>:keys</span> <span class='op'>=&gt;</span> <span class='lbracket'>[</span><span class='symbol'>:id</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:id</span> <span class='op'>=&gt;</span> <span class='int'>1</span><span class='rbrace'>}</span>
  <span class='kw'>begin</span>
    <span class='id identifier rubyid_pushData'>pushData</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>test</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_test_data'>test_data</span><span class='comma'>,</span> <span class='const'>SANDBOX_BASE</span><span class='rparen'>)</span>
  <span class='kw'>rescue</span> <span class='const'>InvalidRequestException</span>
    <span class='kw'>return</span> <span class='kw'>false</span>
  <span class='kw'>end</span>
  <span class='kw'>return</span> <span class='kw'>true</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="pushData-instance_method">
  
    - (<tt>Array</tt>) <strong>pushData</strong>(table_name, data, url = API_BASE) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>Sends data to RJMetrics Data Import API in batches of 100.</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>table_name</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>the table name you wish to store the data</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>data</span>
      
      
        <span class='type'>(<tt>Hashamp</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>or Array of Hashmaps of data points that will get sent</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>url</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
        <em class="default">(defaults to: <tt>API_BASE</tt>)</em>
      
      
        &mdash;
        <div class='inline'>
<p>Import API url</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Array</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>results of each request to RJMetrics Data Import API</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


50
51
52
53
54
55
56
57
58
59
60
61
62
63</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/rjmetrics-client/client.rb', line 50</span>

<span class='kw'>def</span> <span class='id identifier rubyid_pushData'>pushData</span><span class='lparen'>(</span><span class='id identifier rubyid_table_name'>table_name</span><span class='comma'>,</span> <span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='id identifier rubyid_url'>url</span> <span class='op'>=</span> <span class='const'>API_BASE</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_responses'>responses</span> <span class='op'>=</span> <span class='const'>Array</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
  <span class='id identifier rubyid_validatePushDataArgs'>validatePushDataArgs</span><span class='lparen'>(</span><span class='id identifier rubyid_table_name'>table_name</span><span class='comma'>,</span> <span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='id identifier rubyid_url'>url</span><span class='rparen'>)</span>

  <span class='kw'>if</span> <span class='kw'>not</span> <span class='id identifier rubyid_data'>data</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Array</span>
    <span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='const'>Array</span><span class='period'>.</span><span class='op'>[]</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
  <span class='kw'>end</span>

  <span class='id identifier rubyid_data'>data</span><span class='period'>.</span><span class='id identifier rubyid_each_slice'>each_slice</span><span class='lparen'>(</span><span class='const'>BATCH_SIZE</span><span class='rparen'>)</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_batch_data'>batch_data</span><span class='op'>|</span>
    <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>pushing batch of </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_batch_data'>batch_data</span><span class='period'>.</span><span class='id identifier rubyid_count'>count</span><span class='embexpr_end'>}</span><span class='tstring_content'> data points</span><span class='tstring_end'>&quot;</span></span>
    <span class='id identifier rubyid_responses'>responses</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_makePushDataAPICall'>makePushDataAPICall</span><span class='lparen'>(</span><span class='id identifier rubyid_table_name'>table_name</span><span class='comma'>,</span> <span class='id identifier rubyid_batch_data'>batch_data</span><span class='comma'>,</span> <span class='id identifier rubyid_url'>url</span><span class='rparen'>)</span>
  <span class='rbrace'>}</span>
  <span class='kw'>return</span> <span class='id identifier rubyid_responses'>responses</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>

    <div id="footer">
  Generated on Mon Apr  7 11:58:21 2014 by
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.8.7.4 (ruby-2.0.0).
</div>

  </body>
</html>